//
// Created by Yang on 2023/5/28.
//

#include "common.h"
#include "account_item.h"

char readMenuSelection(int options){
    string str;
    while (true) {
        getline(cin, str);

        // 输入合法性校验
        if (str.size() != 1 || str[0] - '0' <= 0 || str[0] - '0' > options) {
            cout << "输入错误，请重新选择！" << endl;
        } else {
            break;
        }
    }

    // 输入合法
    return str[0];
}

char readQuitConfirm(){
    string str;
    while (true) {
        getline(cin, str);

        // 输入合法性校验
        if (str.size() == 1 || toupper(str[0]) == 'Y' || toupper(str[0]) == 'N') {
            break;
        } else {
            cout << "\n输入错误，请重新输入(Y/N)！" << endl;
        }
    }

    // 输入合法
    return toupper(str[0]);
}

int readAmount() {
    int amount;

    string str;
    while (true) {
        getline(cin, str);
        try{
            amount = stoi(str);
            break;
        } catch (invalid_argument argument) {
            cout << "\n输入错误，请输入正确的数字！" << endl;
        }
    }

    // 输入合法
    return amount;
}
